<!DOCTYPE html>
<html>
  <head>
	<meta charset="utf-8">
	<title>管理系统</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
	{:widget_st('layui','css')}
  </head>
{:do_action('admin_head')}
  <style type="text/css">
  	td{
  		    word-break: break-all;
  	}
  </style>

  <body>


  	<div class="">
  		<div class="layui-row">
		    <div class="layui-col-xs12">
		    	<a href="javascript:;" class="layui-btn layui-btn-sm bak_old"> 备份原文件</a>
				  <button class="layui-btn layui-btn-sm" onclick="zfAdminShow('添加','{:url("Zfyun/upgrade_setting")}')">配置</button>

		    	<?php if($upg_msg['code']==1){ ?>
			    	<a href="javascript:;" class="layui-btn layui-btn-sm check_version ">1.下载新版本(默认保存源文件)</a>
			    	<a href="javascript:;" class="layui-btn layui-btn-sm replace_all"> 2.更新全部文件</a>
					<a type="button" class="layui-btn layui-btn-sm" href="{:url('zfyun/upgrade_sql')}">3.执行升级sql</a>

			    	<i class="layui-icon layui-icon-tips" style="font-size: 20px; color: red;"></i> 
			    	发现新版本:{$upg_msg['msg']} (依次执行1.2.3操作) 
		    	<?php }else{ ?>
					<!-- <a type="button" class="layui-btn layui-btn-sm" href="{:url('zfyun/upgrade_sql')}">执行升级sql</a> -->
		    		未发现新版本 当前版本:
		    		{$upg_msg['msg']|raw}
					<a class="layui-btn layui-btn-danger  layui-btn-sm" href="{:url('zfyun/authentication_sys')}">重新授权</a>
				<?php } ?>
				
		    	<!-- <a href="javascript:;" class="layui-btn yun_update"> 下载最新版本</a> -->
		    	<table class="layui-table" lay-skin="line" width="100%" border="1" cellpadding="0" cellspacing="0" style="table-layout:fixed"  lay-size="sm">
				  <colgroup>
				    <col width="50">
				    <col width="150">
				    <col width="150">
				    <col width="150">
				    <col width="80">
				    <col width="80">
				  </colgroup> 
				  <thead>
				    <tr>
				      <th>ID</th>
				      <th>文件名(MD5)</th>
				      <th>原文件路径(/)</th> 
				      <th>更新文件路径<br>(/upgrade/system/new/)</th>
				      <th>是否修改</th>
				      <th>
				      	操作
				      </th>
				    </tr> 
				  </thead>
				  <tbody>
					<?php $i=0;  foreach($ret[1] as $k=>$vo){ ?> 
						<tr> 
						  <td>{++$i}</td> 
						  <td>{$vo['name']}<br>({$vo['md5']})</td> 
						  <td>{$vo['path_new']}</td>
						  <td>{$vo['path_old']}</td>
						  <td>{$vo['is_xg']|raw}</td> 
						  <td>
							  <?php if($vo['is_xg']!='Not changed'){ ?>
								  <a class="layui-btn layui-btn-xs replace_one" href="javascript:;" path_old="{$vo['path_old']}" path_new="{$vo['path_new']}"  >更新</a>
							  <?php } ?>
						  </td> 
						</tr>
						<?php } ?>
						<?php foreach($ret[2] as $k=>$vo){ ?>
						<tr> 
						  <td>{++$i}</td> 
						  <td>{$vo['name']}<br>({$vo['md5']})</td> 
						  <td>{$vo['path_new']}</td>
						  <td>{$vo['path_old']}<br> </td>
						  <td>{$vo['is_xg']|raw}</td>
						  <td>
							<a class="layui-btn layui-btn-xs replace_one" href="javascript:;" path_old="{$vo['path_old']}" path_new="{$vo['path_new']}"  >新增</a>
						  </td> 
						</tr>
						<?php } ?>

				  </tbody>
				</table>
		    </div>
		</div>
  	</div>
	  

    {:widget_st('layui','js')}
  	{:widget_st('common','js')} 

    <!--您的Layui代码start-->
    <script type="text/javascript">
    layui.use([ 'laypage', 'layer', 'table', 'upload', 'element'], function() {
      var $ = layui.$
      ,layer = layui.layer //弹层
      ,table = layui.table //表格
      ,element = layui.element; //元素操作 等等...

      	$('.replace_one').on('click',function(){
      		var file_old = $(this).attr("path_old");
      		var file_new = $(this).attr("path_new");
      		var type = 'replace_one';
		    layer.confirm('确认替换？', {
		        btn: ['确认','取消']
		    }, function(){
				var index = layer.load(0, {shade: false});
		        $.get("{:url('Zfyun/upgrade_act')}",{file_old,file_new,type},function(res){
				layer.close(index); 
		          if(res.result==1){
		            layer.msg(res.msg, {icon: 1});
		            setTimeout(function() {
					  location.reload(true);
		            }, 1000);
		          }else{
		            layer.msg(res.msg, {icon: 2});

		          }
		        },"json");

		    }, function(){
		          //取消的操作
		    });
      	})
      	$('.bak_old').on('click',function(){
      		var type = 'bak_old';
		    layer.confirm('确认备份？', {
		        btn: ['备份','取消']
		    }, function(){
				//执行操作
				var index = layer.load(0, {shade: false});
		        $.get("{:url('Zfyun/upgrade_act')}",{type},function(res){
				layer.close(index); 
		          if(res.result==1){
		            layer.msg(res.msg, {icon: 1});
		            setTimeout(function() {
		              location.reload(true);
		            }, 5000);
		          }else{
		            layer.msg(res.msg, {icon: 2});

		          }
		        },"json");
		    }, function(){
		          //取消的操作
		    });
      	})

      	
      	$('.check_version').on('click',function(){
      		var index = layer.load(0, {shade: false});
      		var type = 'check_version';
	        $.get("{:url('Zfyun/upgrade_act')}",{type},function(res){
	          layer.close(index); 
	          if(res.result==1){
			    layer.msg(res.msg, {icon: 1});
	            setTimeout(function() {
	              location.reload(true);
	            }, 3000);

	          }else{
	            layer.msg(res.msg, {icon: 2});

	          }
	        },"json");
      	})
      // 	$('.yun_update').on('click',function(){
      // 		var type = 'yun_update';
		    // layer.confirm('下载最新版本？', {
		    //     btn: ['下载','取消']
		    // }, function(){
		    //     
		    //     $.get("{:url('Zfyun/upgrade_act')}",{type},function(res){
		    //       if(res.result==1){
		    //         layer.msg(res.msg, {icon: 1});
		    //         setTimeout(function() {
		    //           location.reload(true);
		    //         }, 1000);
		    //       }else{
		    //     	console.log(res.msg);
		    //         layer.msg(res.msg, {icon: 2});

		    //       }
		    //     },"json");
		    // }, function(){
		    //       //取消的操作
		    // });
      // 	})
      	$('.replace_all').on('click',function(){
      		var type = 'replace_all';
		    layer.confirm('替换为最新文件?', {
		        btn: ['替换','取消']
		    }, function(){
				var index = layer.load(0, {shade: false});
		        $.get("{:url('Zfyun/upgrade_act')}",{type},function(res){
				layer.close(index); 
		          if(res.result==1){
		            layer.msg(res.msg, {icon: 1});
		            setTimeout(function() {
		              location.reload(true);
		            }, 1000);
		          }else{
		            layer.msg(res.msg, {icon: 2});
		          }
		        },"json");
		    }, function(){
		          //取消的操作
		    });
      	})

    });
    </script>
  </body>

</html>
{:do_action('admin_js')}